var payment= {};
//所有的支付通道信息
var channels = null;

//获取支付通道
plus.payment.getChannels(function (){
    console.log(JSON.stringify(data));
},function (){
    mui.toast("获取通道失败")
});
    //生成订单号
    payment.orderNumber=function(){
        var random = math.floor(math.random() * 1000000000+1000000000);

        return math.random()+"1";
}
payment.payReq = function (payData,SuccessCB,errorCB){


}
//发送支付请求
function doPay(PayData,SuccessCB,errorCB){
        mui.ajax('https://apisz.beecloud.cn/2/rest/app/bill',{
              data:JSON.stringify(PayData),
             type:'post',
            dataType:'json',
            contentType:'application/json',
            SuccessCB:function (data) {
                  console.log(JSON.stringify(data));{
                      var paySrc = '';
                       if(data.result_code==0){
                           var payChannel = getChannel(payData.channel);
                           //console.log(JSON.stringify(payChannel));
                           if(payChannel) {
                               if(payChannel.id == 'alipay') {
                                   paySrc = data.order_string;
                               }else{
                                   var staement = {
                                       appid: data.app_id ,
                                       noncestr: data.nonce_str,
                                       package:data.package,
                                       partnerid:data.partner_id,
                                       prepayid:data.prepay_id,
                                       timestamp:data.timestamp,
                                       sign:data.pay_sign
                                   };
                                   paySrc= JSON.stringify(staement);


                               }
                               //请求支付
                               plus.payment.request(payChannel,statement,SuccessCB,errorCb);
                           }
                       }
                }
            }

        })
}
//获取到用户点击的那种支付方式的通道
function getChannel(BC_channel){
        var BC_channel_ID = '';
        switch (BC_channel){
            case 'AL_APP':
                BC_channel_ID = 'zfbpay';
                break;
                case 'WX_APP':
                    BC_channel_ID = 'wxpay';
                    break;
        }
        for(var i in channels) {
            if (channels[i].id == BC_channel_ID) {
                return channels[i];
            }
        }

}